//获取控件上绝对位置
function getAbsoluteTop(o) {
	oTop = o.offsetTop;
	while(o.offsetParent!=null){  
		oParent = o.offsetParent; 
		oTop += oParent.offsetTop;  // Add parent top position
		o = oParent;
	}
	return oTop;
}

//获取控件左绝对位置
function getAbsoluteLeft(o) {
	oLeft = o.offsetLeft;
	while(o.offsetParent!=null) {
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft; 
		o = oParent;
	}
	return oLeft;
}


//设置model位置 flow button
function setModelFlowBtn(modalObj, flowBtnObj) {
	var modalJ = getJqueryObj(modalObj);
	var modal = modalJ.get(0);
	
	var flowBtnJ = getJqueryObj(flowBtnObj);
	var flowBtn = flowBtnJ.get(0);
	
	var btnLeft = getAbsoluteLeft(flowBtn);
	//$(window).width() - btnLeft;
	
	/*
	$(window).height();//是文档窗口高度
	$("div").offset().top//是标签距离顶部高度
	$(document).scrollTop();//是滚动条高度
	$("div").height();//是标签高度
	你要的高度+$("div").height()+[$("div").offset().top-$(document).scrollTop()]=$(window).height();
	*/
	
	modal.style.position = "fixed";
	modal.style.top = (getAbsoluteTop(flowBtn)-modalJ.height()/2) + "px";
	//modal.style.left = (btnLeft+ flowBtnJ.width()) + "px";
	modal.style.left = (btnLeft- modalJ.width()) + "px";
	modal.style["z-index"] = 9999;
}

/**
 * 设置modal靠右显示
 */
function setModelFollowRight(modalObj,width){
	var modalJ = getJqueryObj(modalObj);
	var modal = modalJ.get(0);
	modal.style.position = "fixed";
	var modalDJ = modalJ.find(".modal-dialog");
	modalDJ.css({"position":"fixed","top":50,"bottom":0,"right":0,"margin":0,"width":width});
	
	var modalFJ = modalJ.find(".modal-footer");
	modalFJ.css({"position":"fixed","right":"1px","left":"1px","bottom":"1px","margin":0});
	
	var modalBJ = modalJ.find(".modal-body");
	modalBJ.css({"position":"fixed","right":0,"left":0,"top":"50px","bottom":"69px","bottom":"0px","margin":0,"overflow-y":"auto"});
	
	var modalContentJ = modalJ.find(".modal-content");
	modalContentJ.css({"position":"fixed","top":0,"bottom":0,"bottom":0,"margin":0,"width":width});
}



//获得jquery 对象
function getJqueryObj(obj){
	var jObj;
	if (obj.jquery) {
		jObj = obj;
	}else if(obj instanceof HTMLElement){
		jObj = $(obj);
	}else{
		jObj = $("#"+obj);
	}
	return jObj;
}
